from setenv import setLotteryDir
from setenv import getFileDir
from setenv import getFileName

ss_red = {}
ss_blue = {}
guize = {}

filedir = ""
ssqfilename = ""

redAll = 33
blueAll = 16
redNum = 6
blueNum = 1
dqnum = []


def pp(dic):
    for i in dic.keys():
        if dic[i]:
            print(str(i), end=" ")


def csh_guize():
    global guize

    guize[0] = "未中奖"
    guize[10] = "未中奖"
    guize[20] = "未中奖"
    guize[30] = "未中奖"
    guize[40] = "五等奖"
    guize[50] = "四等奖"
    guize[60] = "二等奖"
    guize[1]  = "六等奖"
    guize[11] = "六等奖"
    guize[21] = "六等奖"
    guize[31] = "五等奖"
    guize[41] = "四等奖"
    guize[51] = "三等奖"
    guize[61] = "一等奖"

    setLotteryDir()
    global filedir
    filedir = getFileDir()
    global ssfilename
    ssfilename = getFileName("ssqfilename")
    # print(filedir)
    # print(ssqfilename)
    global dqnum

    with open(str(filedir) + "/" + str(ssfilename), "r") as file:
        # 写入数据
        dqnum = file.read().strip().split(" ")

    file.close
    print("当期中奖号码：" + str(dqnum))


def bijiao(filename):
    global ss_red
    global ss_blue

    for i in range(1, redAll + 1):
        ss_red[i] = False
    for i in range(1, blueAll + 1):
        ss_blue[i] = False

    with open(str(filedir) + "/" + str(filename), "r") as file:
        ss = file.read().strip().split(" ")
    file.close
    #    print(str(ss_sj))
    for i in range(0, redNum):
        ss_red[int(ss[i])] = True

    for i in range(redNum, redNum + blueNum):
        ss_blue[int(ss[i])] = True

    red = 0
    for i in range(0, redNum):
        if ss_red[int(dqnum[i])]:
            red += 1
    blue = 0
    for i in range(redNum, redNum + blueNum):
        if ss_blue[int(dqnum[i])]:
            blue += 1

    result = int(str(red) + str(blue))

    if filename == "ss-sj.txt":
        print("随机选号：")
    if filename == "ss-gd.txt":
        print("固定选号：")

    pp(ss_red)
    pp(ss_blue)

    print("red：" + str(red) + "，blue：" + str(blue) + "。结论：" + guize[result])


if __name__ == '__main__':
    csh_guize()
    bijiao("ss-gd.txt")
    bijiao("ss-sj.txt")
